package demo;

import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.util.Duration;
import javafx.scene.Scene;
import javafx.scene.layout.*;
  
// 面板动态变色
public class PaneColorChanger extends Application {
	private Pane root = new Pane();
	private String[] color1 = {"#ee9ca7", "#1f4037", "#c31432", "#bdc3c7"};
	private String[] color2 = {"#ffdde1", "#99f2c8", "#240b36", "#2c3e50"};
	private int num = -1;
	private Timeline timeline;
	
	public static void main(String[] args) {
		Application.launch(args);
	}
	
	@Override 
	public void start(Stage stage) {
		
		Scene scene = new Scene(root, 600, 400);
		stage.setScene(scene);
		stage.show();
		
		timeline = new Timeline(new KeyFrame(Duration.seconds(2), e ->  {
			num++;
			num%=color1.length;
			root.setStyle("-fx-background-color: linear-gradient( to right," + color1[num] + "," + color2[num] + ")" );
		}));
		timeline.setCycleCount(Timeline.INDEFINITE);
		timeline.play();
	}
}


	
	

		
			
